#!/bin/bash

# 设置环境变量
export LIBGL_ALWAYS_SOFTWARE=1
export MESA_GL_VERSION_OVERRIDE=3.3

echo "===== MuJoCo可视化测试脚本 ====="
echo "这个脚本将测试MuJoCo是否能正常可视化"
echo ""

# 检查MuJoCo是否已安装
echo "检查MuJoCo安装..."
if python -c "import mujoco" 2>/dev/null; then
    echo "✓ MuJoCo已安装"
    MUJOCO_VERSION=$(python -c "import mujoco; print(mujoco.__version__)")
    echo "  MuJoCo版本: $MUJOCO_VERSION"
else
    echo "✗ MuJoCo未安装，请先安装MuJoCo:"
    echo "  pip install mujoco"
    exit 1
fi

# 检查OpenGL环境
echo ""
echo "检查OpenGL环境..."
if command -v glxinfo >/dev/null 2>&1; then
    GL_VENDOR=$(glxinfo | grep "OpenGL vendor" | cut -d":" -f2 | xargs)
    GL_RENDERER=$(glxinfo | grep "OpenGL renderer" | cut -d":" -f2 | xargs)
    GL_VERSION=$(glxinfo | grep "OpenGL version" | cut -d":" -f2 | xargs)
    
    echo "✓ OpenGL信息:"
    echo "  供应商: $GL_VENDOR"
    echo "  渲染器: $GL_RENDERER"
    echo "  版本: $GL_VERSION"
else
    echo "⚠ 无法获取OpenGL信息 (glxinfo未安装)"
    echo "  可以安装mesa-utils包获取glxinfo:"
    echo "  sudo apt-get install mesa-utils"
fi

echo ""
echo "===== 运行测试 ====="

# 运行标准可视化测试
echo ""
echo "1. 运行标准可视化测试 (使用默认后端)..."
# python test_mujoco_visualization.py

# 运行OSMesa渲染测试
echo ""
echo "2. 运行OSMesa软件渲染测试..."
python test_mujoco_osmesa.py

echo ""
echo "测试完成！"
echo "如果测试成功，您应该能看到MuJoCo的可视化窗口和/或生成的渲染图像。"
echo "如果测试失败，请检查错误信息并确保您的系统满足MuJoCo的要求。"
